﻿@{
    var db = new TaoNiuOA.Models.DbEntity();
    var user = new TaoNiuOA.Models.User();
    if (Session["users"] != null)
    {
        user = (TaoNiuOA.Models.User)Session["users"];
    }

    //签到签退
    var today = DateTime.Now.ToString("yyyy-MM-dd");
    var check = db.Checkings.SingleOrDefault(n => n.UserID == user.UserID && n.Date == today);
    var signIn = "";
    var signOut = "";
    if (check != null)
    {
        signIn = check.OnWork;
        signOut = check.OffWork;
    }
}
@if (Session["users"] != null)
{
    <span id="signTip" style="color: Red; margin-right: 30px;"></span>
    if (signIn == "未登记")
    {
    <input type="button" id="signIn" name="signIn" value="签到" />
    }
    else
    {
    <input type="button" id="signIn" name="signIn" value="已签到" disabled="disabled" />
    }
    if (signOut == "未登记")
    {
    <input type="button" id="signOut" name="signOut" value="签退" />
    }
    else
    {  
    <input type="button" id="signOut" name="signOut" value="已签退" disabled="disabled" />
    }

    <text>欢迎 <strong>@user.GetUserInfo().Name</strong>! [<a href="../user/logoff" target="_top">注销</a>]
    </text>
    
    <script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $("#signIn").click(function () {
            if (confirm("您确定上班时间到了么?")) {
                $.post("/checking/sign?mod=signIn", function (data) {
                    if (data == "ok") {
                        $("#signTip").html("签到成功");
                        $("#signIn").attr("disabled", "disabled");
                        $("#signIn").attr("value", "已签到");
                    }
                    else {
                        $("#signTip").html("签到失败");
                    }
                });
            }
        });
        $("#signOut").click(function () {
            if (confirm("您确定下班时间到了么?")) {
                $.post("/checking/sign?mod=signOut", function (data) {
                    if (data == "ok") {
                        $("#signTip").html("签退成功");
                        $("#signOut").attr("disabled", "disabled");
                        $("#signOut").attr("value", "已签退");
                    }
                    else {
                        $("#signTip").html("签退失败");
                    }
                });
            }
        });
    </script>
}
else
{
    @:[ @Html.ActionLink("登录", "LogOn", "user") ]
}
